home *** CD-ROM | disk | FTP | other *** search
/ Die Ultimative Software-P…i Collection 1996 & 1997 / Die Ultimative Software-Pakete CD-ROM fur Atari Collection 1996 & 1997.iso / g / gnu_c / gempp19.zoo / gem++19 / src / grect.cc < prev    next >
Encoding:
C/C++ Source or Header  |  1993-11-02  |  3.1 KB  |  209 lines

  1. /////////////////////////////////////////////////////////////////////////
  2. //
  3. // File:    GRect.cc
  4. //
  5. // Description:    
  6. //        Implementation der Klasse GRect
  7. //
  8. // $Author$
  9. //        ( e-mail:    pareis@cs.tu-berlin.de            )
  10. //        ( NeXT-mail:    subiaagb@w271zrz.zrz.tu-berlin.de    )
  11. //
  12. // $Id$
  13. //
  14. /////////////////////////////////////////////////////////////////////////
  15.  
  16.  
  17. #include "grect.h"
  18.  
  19.  
  20.  
  21.  
  22. ///////////////////
  23. // Konstruktor
  24. ///////////////////
  25.  
  26. GRect::GRect( int x, int y, int w, int h )
  27. {
  28.     g_x = x;
  29.     g_y = y;
  30.     g_w = w;
  31.     g_h = h;
  32. }
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40. ////////////////////////////////////////////////////////////////////////
  41. //
  42. //    Diverse Memberfunktionen
  43. //
  44. ////////////////////////////////////////////////////////////////////////
  45.  
  46.  
  47.  
  48. GRect&    GRect::SetRect( int x, int y, int w, int h )
  49. {
  50.     g_x = x;
  51.     g_y = y;
  52.     g_w = w;
  53.     g_h = h;
  54.     
  55.     return *this;
  56. }
  57.  
  58.  
  59.  
  60.  
  61. GRect& GRect::MoveAbs( int x, int y )
  62. {
  63.     g_x = x;
  64.     g_y = y;
  65.     
  66.     return *this;
  67. }
  68.  
  69.  
  70.  
  71.  
  72. GRect& GRect::MoveRel( int xOffset, int yOffset )
  73. {
  74.     g_x += xOffset;
  75.     g_y += yOffset;
  76.     
  77.     return *this;
  78. }
  79.  
  80.  
  81.  
  82.  
  83. GRect& GRect::Resize( int w, int h )
  84. {
  85.     g_w = w;
  86.     g_h = h;
  87.     
  88.     return *this;
  89. }
  90.  
  91.  
  92.  
  93.  
  94.  
  95. void GRect::GetRect( int& x, int& y, int& w, int& h ) const
  96. {
  97.     GetOrigin( x,y );
  98.     GetSize( w,h );
  99. }
  100.  
  101.  
  102.  
  103.  
  104.  
  105. GRect&    GRect::Clip(const GRect& border)
  106. {
  107.     if (g_x < border.g_x) {
  108.         g_w -= border.g_x-g_x;
  109.         g_x = border.g_x;
  110.     }
  111.  
  112.     if (g_y < border.g_y) {
  113.         g_h -= border.g_y-g_y;
  114.         g_y = border.g_y;
  115.     }
  116.     
  117.     if (g_x+g_w > border.g_x+border.g_w)
  118.         g_w = border.g_x+border.g_w-g_x;
  119.     
  120.     if (g_y+g_h > border.g_y+border.g_h)
  121.         g_h = border.g_y+border.g_h-g_y;
  122.     
  123.     return *this;
  124. }
  125.  
  126.  
  127.  
  128.  
  129. GRect&    GRect::Constrain( const GRect& border )
  130. {
  131.     if (g_x < border.g_x)
  132.         g_x = border.g_x;
  133.  
  134.     if (g_y < border.g_y)
  135.         g_y = border.g_y;
  136.  
  137.     if (g_w <= border.g_w) {
  138.         if (g_x+g_w > border.g_x+border.g_w)
  139.             g_x = border.g_x+border.g_w-g_w;
  140.     } else {
  141.         g_x = border.g_x - (border.g_w-g_w)/2;
  142.     }
  143.     
  144.     if (g_h <= border.g_h) {
  145.         if (g_y+g_h > border.g_y+border.g_h)
  146.             g_y = border.g_y+border.g_h-g_h;
  147.     } else {
  148.         g_y = border.g_y - (border.g_h-g_h)/2;
  149.     }
  150.  
  151.     return *this;
  152. }
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159. ////////////////////////////////////////////////////////////////////////
  160. //
  161. //    Operatoren
  162. //
  163. ////////////////////////////////////////////////////////////////////////
  164.  
  165.  
  166.  
  167. ////////////////////////////////////////////////////////////////////////
  168. //
  169. // SPC: operator==( GRect& other )
  170. //    PRE:    TRUE
  171. //    POST:    g_x==other.g_x AND g_y==other.g_y
  172. //        AND g_w==other.g_w AND g_h==other.g_h
  173. //        -- es muss exakte Uebereinstimmung vorliegen
  174. //
  175. ////////////////////////////////////////////////////////////////////////
  176.  
  177. int GRect::operator==( const GRect& other ) const
  178. {
  179.     return !( *this != other );
  180. }
  181.  
  182.  
  183.  
  184. ////////////////////////////////////////////////////////////////////////
  185. //
  186. // SPC: operator!=( GRect& other )
  187. //    PRE:    TRUE
  188. //    POST:    NOT POST( operator==(GRect& other) )
  189. //
  190. ////////////////////////////////////////////////////////////////////////
  191.  
  192. int GRect::operator!=( const GRect& other ) const
  193. {
  194.     return       g_x^other.g_x | g_y^other.g_y
  195.         | g_w^other.g_w | g_h^other.g_h;
  196. }
  197.  
  198.  
  199.  
  200. GRect&  GRect::Scale(int hscale, int vscale)
  201. {
  202.     g_x*=hscale;
  203.     g_w*=hscale;
  204.     g_y*=vscale;
  205.     g_h*=vscale;
  206.  
  207.     return *this;
  208. }
  209.